﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace Net.Chirash.Twitter.TweetZone.WindowComponents
{
    [ValueConversion(typeof(DateTime), typeof(string))]
    public class DateTimeConverter : IValueConverter
    {
        public object Convert(object value, System.Type targetType,
            object parameter, System.Globalization.CultureInfo culture)
        {
            DateTime arg = (DateTime)value;
            TimeSpan delta = DateTime.Now - arg;
            string ret = "";
            if (delta.TotalSeconds < 60)
            { //1分以下前の場合、"ついさっきと表示"
                return "ついさっき";
            }
            if (delta.Days >= 1)
            {
                ret += delta.Days.ToString() + "日 ";
            }
            if (delta.Hours >= 1)
            {
                ret += delta.Hours.ToString() + "時間 ";
            }
            if (delta.Minutes >= 1)
            {
                ret += delta.Minutes.ToString() + "分";
            }
            ret += "前";
            return ret;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new InvalidOperationException("このメソッドは通常呼び出されません:Net.Chirash.Twitter.TweetZone.WindowComponents.DateTimeConverter.ConvetBack");
        }
    }
}
